# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-listen
pkgver=3.8.0
_commit=fd85e1cb2375767e3cbc4b5743ff50061e8a6c75
pkgrel=2
pkgdesc='The Listen gem listens to file modifications and notifies you about the changes.'
arch=(any)
url='https://github.com/guard/listen'
license=(MIT)
depends=(ruby-rb-fsevent ruby-rb-inotify)
makedepends=(git)
checkdepends=(ruby-rake ruby-rspec ruby-thor)
options=(!emptydirs)
source=(git+https://github.com/guard/listen.git#commit=$_commit)
sha256sums=('SKIP')

prepare() {
  cd listen
  sed -i '/[cC]overalls/d' spec/spec_helper.rb
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd listen
  gem build listen.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    listen-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd listen
  CI=true GEM_HOME="tmp_install/$_gemdir" rake
}

package() {
  cd listen
  cp -a tmp_install/* "$pkgdir"/
  install -Dm644 LICENSE.txt -t "$pkgdir"/usr/share/licenses/$pkgname/
}
